package com.atguigu.day06;

import org.apache.flink.contrib.streaming.state.EmbeddedRocksDBStateBackend;
import org.apache.flink.contrib.streaming.state.RocksDBStateBackend;
import org.apache.flink.runtime.state.filesystem.FsStateBackend;
import org.apache.flink.runtime.state.hashmap.HashMapStateBackend;
import org.apache.flink.runtime.state.memory.MemoryStateBackend;
import org.apache.flink.runtime.state.storage.FileSystemCheckpointStorage;
import org.apache.flink.runtime.state.storage.JobManagerCheckpointStorage;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.io.IOException;

public class Flink14_StatBackend {
    public static void main(String[] args) throws IOException {
        //1.获取流的执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        //TODO 设置状态后端
        //老版本配置方式
        //TODO 内存级别
        env.setStateBackend(new MemoryStateBackend());
        //TODO 文件系统级别
        env.setStateBackend(new FsStateBackend("hdfs://hadoop102:8020/ck"));
        //TODO RocksDB
        env.setStateBackend(new RocksDBStateBackend("hdfs://hadoop102:8020/rocksBd"));



        //新版本设置方式
        //TODO 内存级别
        env.setStateBackend(new HashMapStateBackend());
        //CheckPoint位置
        env.getCheckpointConfig().setCheckpointStorage(new JobManagerCheckpointStorage());

        //TODO 文件系统级别
        env.setStateBackend(new HashMapStateBackend());
        //CK
        env.getCheckpointConfig().setCheckpointStorage("hdfs://hadoop102:8020/ck");
        //或者
        env.getCheckpointConfig().setCheckpointStorage(new FileSystemCheckpointStorage("hdfs://hadoop102:8020/ck"));

        //TODO RocksDB
        env.setStateBackend(new EmbeddedRocksDBStateBackend());
        //CK
        env.getCheckpointConfig().setCheckpointStorage("hdfs://hadoop102:8020/rocksBd");


        //设置不对齐的检查点，Barrier不对齐
        env.getCheckpointConfig().enableUnalignedCheckpoints();

    }
}
